<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            list-style: none;
        }
        
        #pagecut {
            height: 30px;
            display: flex;
            justify-content: start;
            align-items: center;
        }
        
        #pagecut ol {
            display: flex;
        }
        
        #pagecut ol li {
            width: 30px;
            height: 30px;
            border: solid 1px #ddd;
            text-align: center;
            line-height: 30px;
        }
    </style>
</head>

<body>
    <ul id="list"></ul>
    <div id="pagecut">
        <select>
            <option value=2>2</option>
            <option value=5>5</option>
            <option value=10>10</option>
            <option value=15>15</option>
        </select>
        <ol id="page"></ol>
    </div>
    <script src="./page_cut.js"></script>
    <script>
        var obj = new cutPage({
            el: document.getElementById("pagecut"), //类挂载的元素
            data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], //总数据
            pageLength: [2, 5, 10, 15], //每页显示的数据条数；（select框显示的数据）

            //select框中的每页展示条数改变时触发，获取到当前选择的每页显示的条数

            // pagerand: function(data) {
            //     var page = document.getElementById('page');
            //     var pagehtml = ''
            //     for (let i = 0; i < data.pagenum; i++) {
            //         pagehtml += `<li>${i+1}</li>`;
            //     }

            //     var html = ""
            //     data.newdata.forEach(function(v) {
            //         html += `<li>${v}</li>`
            //     });
            //     list.innerHTML = html;
            //     page.innerHTML = pagehtml;
            // },
            cb1: function(data) {
                console.log(data)
                    //obj.pagerand(data)
                var page = document.getElementById('page');
                var pagehtml = ''
                for (let i = 0; i < data.pagenum; i++) {
                    pagehtml += `<li>${i+1}</li>`;
                }

                var html = ""
                data.newdata.forEach(function(v) {
                    html += `<li>${v}</li>`
                });
                list.innerHTML = html;
                page.innerHTML = pagehtml;
            },

            //页码改变时触发，接受到当前页的数据
            cb2: function(data) {
                var page = document.getElementById('page');
                var pagehtml = ''
                for (let i = 0; i < data.pagenum; i++) {
                    pagehtml += `<li>${i+1}</li>`;
                }

                var html = ""
                data.newdata.forEach(function(v) {
                    html += `<li>${v}</li>`
                });
                list.innerHTML = html;
                page.innerHTML = pagehtml;

            }
        })
    </script>
</body>

</html>